<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/15
 * Time: 下午9:07
 */
$str    = "Hello World!";
$result = chunk_split( $str, 5 );
//Hello
// Worl
//d!
echo $result . PHP_EOL;
$result = chunk_split( $str, 5, '-' );
//Hello- Worl-d!-
echo $result . PHP_EOL;

//�,��,��,�,��,��,
echo chunk_split( "新年快乐", 2, ',' ) . PHP_EOL;
//新,年,快,乐,
echo chunk_split( "新年快乐", 3, ',' ) . PHP_EOL;

function chunk_split_unicode( $str, $l = 76, $e = "\r\n" ) {
	$tmp = array_chunk(
		preg_split( "//u", $str, - 1, PREG_SPLIT_NO_EMPTY ), $l );
	$str = "";
	foreach ( $tmp as $t ) {
		$str .= join( "", $t ) . $e;
	}
	
	return $str;
}

//新年,快乐,
echo chunk_split_unicode( "新年快乐", 2, ',' ) . PHP_EOL;
